/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.shop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.shop.HkEnterShopCompanyInfo;
import com.thinkgem.jeesite.modules.hk.shop.service.shop.HkEnterShopCompanyInfoService;

/**
 * 店铺企业信息Controller
 * @author 李欣荣
 * @version 2018-10-08
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/shop/hkEnterShopCompanyInfo")
public class HkEnterShopCompanyInfoController extends BaseController {

	@Autowired
	private HkEnterShopCompanyInfoService hkEnterShopCompanyInfoService;
	
	@ModelAttribute
	public HkEnterShopCompanyInfo get(@RequestParam(required=false) String id) {
		HkEnterShopCompanyInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkEnterShopCompanyInfoService.get(id);
		}
		if (entity == null){
			entity = new HkEnterShopCompanyInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:shop:hkEnterShopCompanyInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkEnterShopCompanyInfo hkEnterShopCompanyInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkEnterShopCompanyInfo> page = hkEnterShopCompanyInfoService.findPage(new Page<HkEnterShopCompanyInfo>(request, response), hkEnterShopCompanyInfo); 
		model.addAttribute("page", page);
		return "hk/shop/shop/hkEnterShopCompanyInfoList";
	}

	@RequiresPermissions("shop:shop:hkEnterShopCompanyInfo:view")
	@RequestMapping(value = "form")
	public String form(HkEnterShopCompanyInfo hkEnterShopCompanyInfo, Model model) {
		model.addAttribute("hkEnterShopCompanyInfo", hkEnterShopCompanyInfo);
		return "hk/shop/shop/hkEnterShopCompanyInfoForm";
	}

	@RequiresPermissions("shop:shop:hkEnterShopCompanyInfo:edit")
	@RequestMapping(value = "save")
	public String save(HkEnterShopCompanyInfo hkEnterShopCompanyInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkEnterShopCompanyInfo)){
			return form(hkEnterShopCompanyInfo, model);
		}
		hkEnterShopCompanyInfoService.save(hkEnterShopCompanyInfo);
		addMessage(redirectAttributes, "保存店铺企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkEnterShopCompanyInfo/?repage";
	}
	
	@RequiresPermissions("shop:shop:hkEnterShopCompanyInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(HkEnterShopCompanyInfo hkEnterShopCompanyInfo, RedirectAttributes redirectAttributes) {
		hkEnterShopCompanyInfoService.delete(hkEnterShopCompanyInfo);
		addMessage(redirectAttributes, "删除店铺企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkEnterShopCompanyInfo/?repage";
	}

}